<template lang='pug'>
</template>
<script>
export default {
  name: "c_tech_label",
  data() {
    return {
      viewer: null,
      Cesium: null,
      c_tech_label: null,
    };
  },
  props: {
    arrda: {
      type: Array,
      default: [], //[{llh:[130,24,1],txt:'示例',img:''}]
    },
  },
  watch: {
    arrda: {
      handler() {
        if (this.Cesium && this.viewer) this.load();
      },
    },
    deep: true,
  },
  mounted() {
    let t = this;
    t.$nextTick(() => {
      t.viewer = t.$parent.viewer;
      t.Cesium = t.$parent.Cesium;
      let { Cesium, viewer } = this;
      t.gp_tech_label = new Cesium.CustomDataSource("tech_label");
      viewer.dataSources.add(t.gp_tech_label);
      t.load();
    });
  },
  methods: {
    load() {
      let t = this;
      let { Cesium, viewer } = this;
      if (!this.gp_tech_label) {// 设置一个实例
        this.gp_tech_label = new Cesium.CustomDataSource("tech_label");
      }
      this.gp_tech_label.entities.removeAll();
      for (let i = 0; i < this.arrda.length; i++) {
        let da=this.arrda[i]
        let name=`tech_label`,label={}
        let [lon,lat,hei]=da.llh
        let position=Cesium.Cartesian3.fromDegrees(lon,lat,hei)
        label = {
          text: da.txt, // "文字标签"
          font: "24px Yahei",
          scale: 0.7,
          pixelOffset: da.img?new Cesium.Cartesian2(0, -24):new Cesium.Cartesian2(0, 0), // 像素偏移
        }
        if(da.img){
           let billboard={
              image: da.img,
              width: 24,
              height: 24,
              disableDepthTestDistance: Number.POSITIVE_INFINITY, //返回正无穷大
            }
          this.gp_tech_label.entities.add({name,position,label,billboard});
        }else{
          this.gp_tech_label.entities.add({name,position,label});
        }
        
      }
    },
  },
};
</script>